add_custom_target(lib)

##################### Target sources ###########
set(LIB_TARGET_SOURCES)

add_subdirectory(common)
add_subdirectory(detector)
add_subdirectory(nvidia)
add_subdirectory(preprocess)
add_subdirectory(postprocess)
add_subdirectory(visualization)

list(APPEND LIB_TARGET_SOURCES)

set(LIB_TARGET_SOURCES ${LIB_TARGET_SOURCES}
    e2e_processor.cpp
    data_adapter.cpp)
######################## STATIC LIBRARY #######################

add_library(${LIB_TARGET_NAME} STATIC
    ${LIB_TARGET_SOURCES})

set_target_properties(${LIB_TARGET_NAME} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    COMPILE_FLAGS "-O2"
    ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
    RUNTIME_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}"
)

set_target_properties(${LIB_TARGET_NAME} PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL -Wl")
set_target_properties(${LIB_SHARED_TARGET} PROPERTIES DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX})
set_target_properties(${LIB_TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

##########################################

add_dependencies(lib ${LIB_TARGET_NAME})

##########################################

# install(TARGETS ${LIB_TARGET_NAME}
#         RUNTIME DESTINATION bin
#         LIBRARY DESTINATION lib
#         ARCHIVE DESTINATION lib
# )

###############################################################################

#################################### BUILD EXEC ###############################

add_executable(${TARGET_NAME} 
    main.cpp
    )
    
set_target_properties(${TARGET_NAME} PROPERTIES
    CXX_STANDARD "17"
    CXX_STANDARD_REQUIRED "YES"
    CXX_EXTENSIONS "NO"
    COMPILE_FLAGS "-O2"
    ARCHIVE_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    LIBRARY_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    RUNTIME_OUTPUT_DIRECTORY "${TARGET_OUT_DIR}"
    DEBUG_POSTFIX ${TARGET_DEBUG_POSTFIX}
    VERSION ${PROJECT_VERSION}
    INSTALL_RPATH "bin"
)

target_link_libraries(
  ${TARGET_NAME}
  ${LIB_TARGET_NAME}
  log4cxx 
  boost_json
  nvinfer
  nvonnxparser
  pthread
  ${PERCEPTION_DATASET_LIB}
  ${PERCEPTION_MAP_LIB}
  ${CMAKE_THREAD_LIBS_INIT}
  ${OpenCV_LIBS}
  ${CUDA_LIBRARIES}
  ${PCL_LIBRARIES}
  ${VTK_LIBRARIES}
)

vtk_module_autoinit(
  TARGETS ${TARGET_NAME}
  MODULES ${VTK_LIBRARIES}
)

install(TARGETS ${TARGET_NAME}
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
)
